#include <stdio.h>
#include <string.h>

int w, h, i, j, k;
int v[110][110];
int ans[110][110], maxv;
int movex[]={-1,0,0,1};
int movey[]={0,-1,1,0};

int dp(int x, int y) {
    int i, j, tox, toy, mm;
    if (ans[x][y]!=0) 
        return ans[x][y];
    mm = 0;
    for (i=0; i<4; ++i)
    {
        tox = x + movex[i];
        toy = y + movey[i];
        if (tox>=0 && toy>=0 && tox<h && toy<w && v[x][y] > v[tox][toy]) {
            j = dp(tox, toy);
            if (mm < j) mm = j;
        }    
    }    
    return ans[x][y] = mm+1;
}     

int main()
{
    
    while (scanf("%d%d", &h, &w)!=EOF) {
        memset(ans, 0, sizeof(ans));
        maxv = 0;
        for (i=0; i<h; ++i)
            for (j=0; j<w; ++j) {
                scanf("%d", &v[i][j]);
            }       
        for (i=0; i<h; ++i)
            for (j=0; j<w; ++j) {
                dp(i, j);
                if (maxv < ans[i][j]) maxv = ans[i][j];
            }    
        printf("%d\n", maxv);
    }    
    
    return 0;
}    
